<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = 'asdgsde';

        String.prototype.sub = function (a, b) {
            var str1 = '';
            a = a == undefined ? 0 : a;
            b = b == undefined ? this.length : b;

            for (i = a; i < this.length; i++) {
                if (i == b) {
                    return str1
                } else {
                    str1 += this[i];
                }


            }
            return str1
        }
        console.log(str.sub(2, 4))
    </script>
</body>

</html>